import java.util.ArrayList;

/**
 * 
 * @author Devin Wolanick
 * @Version 1.0
 * 
 * ManuPlayer is a Manual Card Player
 */
public class ManuPlayer implements BlackJackPlayer{
	
	/**
	 * Variables
	 */
	private ArrayList<Card> myHand = new ArrayList<Card>();
	
	/**
	 * Request Action from Player                    NOT BEING USED!
	 */
/*	public int requestAction(ArrayList<Integer> dealersHand) {	
		InputStreamReader converter = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(converter);
		String userInput = null;
		int returnCommand = -1;
		
		displayHand();
		displayValue();
		displayDealerHand(dealersHand);
		if (busted())
			return 3;
		System.out.print("Action? (1 Hit) (2 Pass):");
		try {
			userInput = in.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
		returnCommand = Integer.parseInt(userInput);
		} catch (Exception e) {
			System.out.println("Invalid Selection");
			System.exit(1);
		}
		if (returnCommand<1 || returnCommand >2) {
			System.out.println("Invalid Selection");
			System.exit(1);
		}
		return returnCommand;
	}*/
	
	/**
	 * Evaluates Hand Value
	 * @return List of possible Values
	 */
	public ArrayList<Integer> evaluateHand(){
		EvaluateHand evaluator = new EvaluateHand(myHand);
		return evaluator.evaluate();
	}
	
	/**
	 * Displays Hand                           NOT BEING USED!
	 */
/*	private void displayHand() {
		System.out.print("You Hold: ");
		for (int i=0; i<myHand.size(); i++) {
			int cardNum  = myHand.get(i).getNumber();
			int cardSuit = myHand.get(i).getSuit();
			System.out.print(cardNumbers[cardNum-1]+" of "+cardSuits[cardSuit-1]+ "   ");
		}
		System.out.println();
	}*/
	
	/**
	 * Displays Hand Value                  NOT BEING USED!
	 */
/*	private void displayValue() {
		System.out.println("Your Hand Value(s): "+ evaluateHand().toString());
	}*/
	
	/**
	 * Displays Dealers Hand                  NOT BEING USED!
	 * @param dealersHand Dealers Hand
	 */
/*	private void displayDealerHand(ArrayList<Integer> dealersHand) {
		System.out.println("Dealers Face up Value: "+ dealersHand);
	}*/
	
	/**
	 * Discards Hand
	 */
	public void discardHand() {
		myHand.clear();
	}
	
	/**
	 * Check if Player Busted
	 * @return True if Busted
	 */
	public boolean busted() {
		int maxValue = 22;
		ArrayList<Integer> possibleValues = evaluateHand();
		for (int i=0; i<possibleValues.size(); i++)
			if (possibleValues.get(i)<maxValue)
				maxValue = possibleValues.get(i);
		if (maxValue>21)
			return true;
		return false;
	}
	
	/**
	 * Returns Players Hand
	 * @return List of Cards
	 */
	@SuppressWarnings("unchecked")
	public ArrayList<Card> getHand() {
		return (ArrayList<Card>) myHand.clone();
	}

	/**
	 * Receive a Card
	 * @param someCard Card to receive
	 */
	public void receiveCard(Card someCard) {
		myHand.add(someCard);
	}
}
